﻿using System;
using System.Collections.Generic;
using Contracts.Entities;
using Contracts.Library;
using Definition.WebImport;

namespace Client.Processes
{
    public class ImportWebInfos
    {
        private Asynchronizer<IEnumerable<MovieItem>> async;
        private Synchronizer<TmdbResult> sync;
        private TmdbImport import;

        public ImportWebInfos()
        {
            this.async = new Asynchronizer<IEnumerable<MovieItem>>(true);
            this.sync = new Synchronizer<TmdbResult>();
            this.import = new TmdbImport();

            async.OnProcessing += import.Process;
            import.OnResult += sync.Process;
            sync.OnCompleted += (m) => OnResult(m);
        }

        public void Process(IEnumerable<MovieItem> items)
        {
            async.Process(items);
        }

        public event Action<TmdbResult> OnResult;
    }
}
